package com.paipai.config;

import com.paipai.ws.WsHandler;
import com.paipai.ws.WsInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
public class WsConfig implements WebSocketConfigurer {
    @Autowired
    WsHandler wsHandler;
    @Autowired
    WsInterceptor wsInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        //消息处理器，握手拦截器
        webSocketHandlerRegistry.addHandler(wsHandler, "/p").addInterceptors(wsInterceptor).setAllowedOrigins("*");
    }
}
